//
//  PickGoodsViewController.m
//  YiBaoStore
//
//  Created by 吕清毅 on 2018/11/24.
//  Copyright © 2018年 小河. All rights reserved.
//

#import "PickGoodsViewController.h"

@interface PickGoodsViewController ()

@property (nonatomic,strong) UIButton *sureBtn;
@end

@implementation PickGoodsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
   // self.view.backgroundColor = HexWithAlpha(0x000000, 0.6);
    [self setMainView];
}

- (void)setMainView
{
    UIView *backView = [UIView new];
    backView.frame = CGRectMake(50, 105+TopStatusHeight, SCREENWIDTH-100, 435);
    backView.backgroundColor = TotalWhite;
    backView.layer.cornerRadius = 12;
    [self.view addSubview:backView];
    
    UILabel *titleLab = [UILabel new];
    titleLab.frame = CGRectMake(0, 20, backView.width, 14);
    titleLab.textColor = titleColor;
    titleLab.font = FontSemiboldSize(14);
    titleLab.text = @"待取件";
    titleLab.textAlignment = NSTextAlignmentCenter;
    [backView addSubview:titleLab];
    
    UIImageView *close = [UIImageView new];
    close.frame = CGRectMake(backView.width-36, 20, 16, 16);
    close.image = [UIImage imageNamed:@"anClose"];
    [backView addSubview:close];
    
    UIButton *closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    closeBtn.frame = CGRectMake(close.left-5, 15, 26, 26);
    [closeBtn addTarget:self action:@selector(close) forControlEvents:UIControlEventTouchUpInside];
    [backView addSubview:closeBtn];
    
    UIImageView *goodsIV = [UIImageView new];
    goodsIV.frame = CGRectMake(20, titleLab.bottom+10, 235, 235);
    goodsIV.backgroundColor = [UIColor clearColor];
    [goodsIV sd_setImageWithURL:[NSURL URLWithString:self.dict[@"itemShowImage"]]placeholderImage:[UIImage imageNamed:@"Placeholder400"]];
    goodsIV.contentMode = UIViewContentModeScaleAspectFill;
    [backView addSubview:goodsIV];
    
    UILabel *goodsTitleLab = [UILabel new];
    goodsTitleLab.frame = CGRectMake(goodsIV.left, goodsIV.bottom+5, backView.width-40, 34);
    goodsTitleLab.numberOfLines = 0;
    goodsTitleLab.textColor = titleColor;
    goodsTitleLab.font = FontWithSize(14);
    goodsTitleLab.attributedText = [TTKUtil getAtttributeStringWithLineSpace:0 kern:1 and:self.dict[@"itemTitle"]];
    [backView addSubview:goodsTitleLab];
    
    UILabel *numLab = [UILabel new];
    numLab.frame = CGRectMake(backView.width-100, goodsTitleLab.bottom+26, 80, 14);
    numLab.textColor = titleColor;
    numLab.font = FontWithSize(14);
    numLab.text = [NSString stringWithFormat:@"¥%.2f  *%li",[self.dict[@"itemPrice"]doubleValue],[self.dict[@"itemBuyAmount"]integerValue]];
    numLab.textAlignment = NSTextAlignmentRight;
    [backView addSubview:numLab];
    
    UILabel *countLab = [UILabel new];
    countLab.frame = CGRectMake(backView.width-270, numLab.bottom+10, 250, 14);
    countLab.textColor = titleColor;
    countLab.font = FontSemiboldSize(14);
    countLab.textAlignment = NSTextAlignmentRight;
    double price = [self.dict[@"itemPrice"]doubleValue] * [self.dict[@"itemBuyAmount"]integerValue];
    countLab.text = [NSString stringWithFormat:@"总计：¥%.2f",price];
    [backView addSubview:countLab];
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(0, backView.height-44, backView.width, 44);
    btn.backgroundColor = UIColorFromHex(0xF7D553);
    [btn setTitleColor:titleColor forState:UIControlStateNormal];
    btn.titleLabel.font = FontSemiboldSize(12);
    //设置按钮的下部分切圆角
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:btn.layer.bounds byRoundingCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight cornerRadii:CGSizeMake(10.f,10.f)];
    CAShapeLayer *maskLayer = [CAShapeLayer new];
    maskLayer.frame = btn.layer.bounds;
    maskLayer.path = maskPath.CGPath;
    btn.layer.mask = maskLayer;
    [btn setTitle:@"确认" forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(next) forControlEvents:UIControlEventTouchUpInside];
    self.sureBtn = btn;
    [backView addSubview:btn];
}

- (void)next
{
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setValue:[NSNumber numberWithInteger:self.orderId] forKey:@"orderId"];
    [dict setValue:self.code forKey:@"code"];
    [HttpRequest formPostPath:Confirm_delivery_API params:dict resultBlock:^(id Data, MsgModel *msgModel) {
        [self ShowHUDWithMessage:@"取件成功"];
        [self.view removeFromSuperview];
        [self.vc.view removeFromSuperview];
    }];
}

- (void)close
{
    [self.view removeFromSuperview];
}

- (void)ShowHUDWithMessage:(NSString *)message
{
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow animated:YES];
    hud.mode = MBProgressHUDModeCustomView;
    hud.bezelView.backgroundColor = UIColorFromHex(0xFF9D9D9D);
    hud.contentColor = [UIColor whiteColor];
    hud.label.text = NSLocalizedString(message, nil);
    hud.label.font = FontWithSize(12);
    [hud hideAnimated:YES afterDelay:HUDTime];
}
@end
